<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<script type="text/javascript" >

function searchUser(node){
	$('#userGrid').datagrid('reload',params);
};



$(function(){
	$('#userGrid').datagrid({
	    url: ctx + '/sm/User!findByPage.action',
	    singleSelect: true,
	    fit: true,
	    pagination: true,
	    toolbar:'#button_index',
	    rownumbers: true,
	    initload: false,
	    idField: 'sid',
	    onDblClickRow :function(rowIndex,rowData){
	    	CQOA.load('extendDiv',ctx+'/sm/User!operate.action',{'entity.sid':rowData.sid},function(){
				CQOA.hideDiv('mainDiv');
				CQOA.showDiv('extendDiv');
			});
	    }
	});
	
	$('#userOrgTree').tree({
		url: ctx + '/sm/Org!findChildTree.action?_json=json',
        fit: true,
        idField: 'id',
        treeField: 'text',
        onClick:function(node){
        	//console.log(node);
        	$('#userGrid').datagrid('reload',{'deptId':node.id});
        }
	});

	$('#userSearch').bind('click',function(){
		$('#userGrid').datagrid('reload',{
			'entity.username':$('#searchUserName').val(),
			'entity.cname':$('#searchCName').val()
		});
	});
	
	$('#userReset').bind('click',function(){
		$('#searchUserName').val('');
		$('#searchCName').val('');
	});
	
	$('#userAdd').bind('click',function(){
		var row = $('#userOrgTree').tree('getSelected');
		if (!row) {
			$.messager.show({
				msg : '请选择一部门'
			});
			return false;
		}
		CQOA.load('extendDiv',ctx+'/sm/User!operate.action',{
			'deptId':row.id,
			'deptCname':row.text
		},function(){
			CQOA.hideDiv('mainDiv');
			CQOA.showDiv('extendDiv');
		});
	});
	$('#userEdit').bind('click',function(){
		var row = $('#userGrid').datagrid('getSelected');
		if (!row) {
			$.messager.show({
				msg : '请选择一条数据'
			});
			return false;
		}
		CQOA.load('extendDiv',ctx+'/sm/User!operate.action',{'entity.sid':row.sid},function(){
			CQOA.hideDiv('mainDiv');
			CQOA.showDiv('extendDiv');
		});
	});
	$('#userDel').bind('click',function(){
		var row = $('#userGrid').datagrid('getSelected');
		if (!row) {
			$.messager.show({
				msg : '请选择一条数据'
			});
			return false;
		}
		$.messager.confirm('提示信息','你确定要删除这条数据?',function(res){
			if(res){
				postcommit(ctx+'/sm/User!delete.action',{'entity.sid':row.sid},function(o){
					if(o.success){
						$('#userGrid').datagrid("unselectAll");
						$('#userGrid').datagrid('reload');
					}
					$.messager.show({
						msg : o.msg
					});
				});
			}
		});
		
		
	});
});

function comeback(){
	CQOA.hideDiv('extendDiv');
	CQOA.showDiv('mainDiv');
};

function user_save(){
	CQOA.formSubmit($('#userOperateForm'),ctx+'/sm/User!save.action',function(o){
		if(o.success){
			comeback();
			$('#userGrid').datagrid('reload');
		}
		$.messager.show({
			msg : o.msg
		});
	},{});
};
</script>
<div id="mainDiv" class="easyui-layout" fit="true" border="false" style="width: 100%;height: 100%">
	        <div id="easyui-title" style="display:none">
	            	用户设置
	        </div>
	        <div region="west" style="width:180px;padding1:1px;overflow:auto;" >
	       		 <ul id="userOrgTree" class="easyui-tree"></ul>
	        </div>
	        <div region="north" style="height:30px;" border="false" >
	        	<div class="searchDiv" region="north" border="false" style="text-align: center;">
	        		 帐号:<input id="searchUserName" class="easyui-validatebox"  validType="length[1,100]" style="width: 200px;">                
	               	 姓名:<input id="searchCName" class="easyui-validatebox"  validType="length[1,100]"  style="width: 200px;">
	               	 <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="userSearch">查询</a>
	               	 <a href="#" class="easyui-linkbutton" iconCls="icon-reload" id="userReset">重置</a>
            	</div>
	        </div>
	        <div id="button_index" class="top_toolbar_button_div" border="false">
	                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" id="userAdd">新增</a>
	                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" id="userEdit">修改</a>
	                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" id="userDel">删除</a>
	         </div>
            <div  region="center" border="false" style="width: 100%;height: 100%">
            		<table id="userGrid" title="用户数据" border="false" fit="true" style="width: 100%;height: 100%">
		               			<thead>
				                   <tr>
				                   	  <!-- 
				                      <th field="sid"  width="50">SID</th>
				                       -->
				                      <th field="username"  width="200">帐号</th>
				                      <th field="cname"  width="200">姓名</th>
				                      <th field="email"  width="200">邮箱</th>
				                      <th field="mobile"  width="200">电话</th>
				                      <th field="createdt" width="150">创建时间</th>
				                   </tr>
		               			</thead>
		       	 	</table>
           </div>
</div>
<div id="extendDiv" class="easyui-panel" style="display:none;" fit="true" border="false"></div>


